<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>e网批发管理后台</title>
  <?php include("common/conn.php"); if($_SESSION['userid']==""){echo "<script>window.location.href='login.php';</script>";} 

//删除
  if($_GET['del']=="ok"){
    $area = array(); 
    $area= $_POST['checkbox'];

    foreach ($area as $k=>$v){
      $srat1=mysql_query("DELETE FROM goods where goodsid='".$v."'");
    }
    if ($_GET['shopid']!='') {
      echo "<script>alert('删除成功');window.location.href='shouxuanjingpin_goods.php?shopid=".$_GET['shopid']."'</script>";
    }else{
      echo "<script>alert('删除成功');window.location.href='shouxuanjingpin_goods.php'</script>";
    }
    

  }


// 一键审核通过 
if ($_REQUEST['act'] == 'passall') {
  $goodsids = $_REQUEST['goodsids'];
  $query = mysql_query("UPDATE goods set `check` = 1 where goodsid in (".$goodsids.")");
  echo "<script>alert('修改成功');window.location.href='shouxuanjingpin_goods.php'</script>";
}
// 一键审核通过 end


// 是否通过审核
if ($_REQUEST[check]!='') {
  mysql_query("UPDATE goods set `check`=".$_REQUEST[check]." where goodsid=".$_REQUEST[goodsid]);
  echo "<script>window.location.href='shouxuanjingpin_goods.php'</script>";
}
// 是否通过审核 end


//选为广告
/*if($_GET['ad']!=""){

    $srat1=mysql_query("update goods set ad='".$_REQUEST['ad']."' where goodsid='".$_REQUEST['id']."'");
    if($_GET['ad']!="0")
    { 
      echo "<script>window.location.href='addad.php?goodsid=$_REQUEST[id]&id=$_REQUEST[gid]';</script>";
    }


  }

  if ($_GET['cancel']='ok') {
    $srat1=mysql_query("DELETE FROM ad where id='".$_GET['id']."'");
  }*/

  //选为特价
  if($_GET['tejia']!=""){
    $srat1=mysql_query("update goods set tejia='".$_REQUEST['tejia']."' where goodsid='".$_REQUEST['goodsid']."'");
    //拿到特价商品
    $goodsid = mysql_query("select * from goods where goodsid=".$_REQUEST['goodsid']);
    $goods = mysql_fetch_array($goodsid);
    $date = date('Y/m/d',time());
    $addtime = time();
    $cate = $goods['xilie'].','.$goods['zixilie'];
    $tejiatime = mysql_query("INSERT INTO tejia_time(`time_quyu`,`time_goodsid`,`time_date`,`time_shopid`,`time_categroy`,`time_addtime`) VALUES('$goods[city]','$goods[goodsid]','$date','$goods[shopid]','$cate','$addtime')");
  }



  //选为喜欢
  if($_GET['xihuans']!="")
  {    
    $srat1=mysql_query("update goods set xihuan='".$_REQUEST['xihuans']."' where goodsid='".$_REQUEST['id']."'");
  }
  //选为扫货
  if($_GET['act_saohuo']!="")
  {  
    $srat1=mysql_query("update goods set act_saohuo='".$_REQUEST['act_saohuo']."' where goodsid='".$_REQUEST['id']."'");
  }

  //选为限时折扣
  if($_GET['act_xianshizhekou']!="")
  {    
    $srat1=mysql_query("update goods set act_xianshizhekou='".$_REQUEST['act_xianshizhekou']."' where goodsid='".$_REQUEST['id']."'");
  }

  //选为首选精品
  if($_GET['act_shouxuanjingpin']!="")
  {    
    $srat1=mysql_query("update goods set act_shouxuanjingpin='".$_REQUEST['act_shouxuanjingpin']."' where goodsid='".$_REQUEST['id']."'");
  }

  //选为你想要的
  if($_GET['act_nixiangyaode']!="")
  {    
    $srat1=mysql_query("update goods set act_nixiangyaode='".$_REQUEST['act_nixiangyaode']."' where goodsid='".$_REQUEST['id']."'");
  }

/*// 选为推荐和取消推荐
if (isset($_REQUEST[recommend])) {
  $query = mysql_query("UPDATE goods set recommend='".$_REQUEST[recommend]."' where goodsid=".$_REQUEST[goodsid]);
  echo "<script>window.location.href='shouxuanjingpin_goods.php'</script>";
}
// 选为推荐和取消推荐 end

// 选为推荐和取消推荐
if (isset($_REQUEST[tejia])) {
  $query = mysql_query("UPDATE goods set tejia='".$_REQUEST[tejia]."' where goodsid=".$_REQUEST[goodsid]);
  echo "<script>window.location.href='shouxuanjingpin_goods.php'</script>";
}
// 选为推荐和取消推荐 end*/

  ?>
  <script type="text/javascript" src="js/jquery.min.js"></script>
  <link href="css/styles.css" rel="stylesheet" type="text/css" />
  <link href="css/style2.css" rel="stylesheet" type="text/css" />
  <script type="text/JavaScript">
      function MM_jumpMenu(targ,selObj,restore){ //v3.0
        eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
        if (restore) selObj.selectedIndex=0;
      }
</script>
</head>

<body>

  <!--header-->
  <?php include("common/header.php");?>
  <!--header end-->

  <!-- staqrt subnav -->
  <div id="sub_nav">

    <div id="subnav_wrap" class="container_12">
      <div id="subnav" class=" grid_12">
        <ul>
          <li><a href="shouxuanjingpin.php?type=3">属性设置</a></li>
          <li><a href="shouxuanjingpin_img.php?type=3">分类活动图片</a></li>
          <li><a href="shouxuanjingpin_goods.php?type=3"  class="sub_nav_active">商品管理</a></li>
        </ul>
      </div>

    </div>


  </div>
  <div class="container_12">
    <form action="?id=<?php echo $_REQUEST[id]; ?>" method="post">
      <label>市场</label>
      <select name="classify" class="select" onchange="MM_jumpMenu('parent',this,0)">
        <?php if (!isset($_GET[cityid]) ) {?>
        <option value="?path=<?php echo $_GET[path]; ?>">全部市场</option>
        <?php }?>
        <?php if($_GET[cityid]!=""){?>
        <option value="?path=<?php echo $_GET[path]; ?>">全部市场</option>
        <?php }else{?>
        <?php } $rert32=mysql_query("select * from city order by id desc ");
        while($sdg32=mysql_fetch_array($rert32)){
          $query=mysql_query("select * from shop where shopid='".$_GET[shopid]."'");
          $result=mysql_fetch_array($query);
          ?>                  
          <option  value="?city=<?php echo $sdg32[city];?>&cityid=<?php echo $sdg32[id];?>" <?php if ($sdg32[id]==$_REQUEST[cityid]) { ?>selected<?php } ?>><?php echo $sdg32[city];?></option>
          <?php }?>

        </select>

        <label>商家</label>
        <select name="classify" class="select" onchange="MM_jumpMenu('parent',this,0)">
          <?php if (!isset($_GET[shopid])) {?>
          <option value="?path=<?php echo $_GET[path]; ?>&cityid=<?php echo $_REQUEST[cityid]; ?>">全部商家</option>
          <?php }?>
          <?php if($_GET[shop]!=""){?>
          <!-- <option  value="?brand=<?php echo $_GET[shop];?>"> -->
          <option value="?path=<?php echo $_GET[path]; ?>&cityid=<?php echo $_REQUEST[cityid]; ?>">全部商家</option>
          <?php echo $_GET[shop];?></option>
          <?php }else{?>            
          <?php } 
          $_sql = "select * from shop ";
          if($_GET[cityid]!=""){
            $_sql.=" where city=$_GET[cityid]";
          }
          $_sql.=" order by shopid desc ";
          $rert32=mysql_query($_sql);
          while($sdg32=mysql_fetch_array($rert32)){?>
          <option <?php if ($sdg32[shopid]==$_REQUEST[shopid]) { ?>selected<?php } ?> value="?cityid=<?php echo $_REQUEST[cityid]; ?>&shopid=<?php echo $sdg32[shopid];?>&shop=<?php echo $sdg32[name];?>"><?php echo $sdg32[name];?></option>
          <?php }?>

        </select>
        <input type="button" class="submit" value="新增商品" onclick="add();">
        <input  type="text" class="text" placeholder="商品关键字/商家编码"  name="keywords"  value="<?php echo $_REQUEST[keywords]; ?>"/>

        <input name="" type="submit" class="submit" value="搜索商品" /> 
      </form>
    </div>
    <!-- end sub_nav -->
    <form id="form"  action="?del=ok&shopid=<?php echo $_REQUEST[shopid]; ?>" method="post">
      <!-- EVERYTING BELOW IS THE MAIN CONTENT -->


      <table width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <th width="2%" scope="col">
            <input type="checkbox" id="checkbox" class="checkall" />全选&nbsp;&nbsp;
          </th>
          <th width="10%" scope="col">是否通过审核</th>
          <th width="8%" scope="col">审核状态</th>
          <th width="8%" scope="col">营销</th>
          <th width="8%" scope="col">市场</th>
          <th width="8%" scope="col">商家</th>
          <th width="3%" scope="col">点赞</th>
          <th width="10%" scope="col">图 </th>
          <th width="10%" scope="col">标题</th>
          <th width="10%" scope="col">分类</th>
          <th width="10%" scope="col">出售价格</th>
          <th width="5%" scope="col">销量</th>
          <th width="15%" scope="col">操作</th>
        </tr>

<?php 
mysql_query('SET NAMES UTF8');  

$ren="1";
$sex="0";
$perNumber=20; //每页显示的记录数
$page=$_GET['page']; //获得当前的页面值
if($_REQUEST[keywords]!="")
{
  $count=mysql_query("select count(*) from goods  JOIN shop ON shop.shopid=goods.shopid  where act_shouxuanjingpin=2  and title like '".$_REQUEST[keywords]."%'  OR  shop.tel LIKE '".$_REQUEST[keywords]."%' OR shop.phone LIKE '".$_REQUEST[keywords]."%' ");

}
else if($_REQUEST[shopid]!=""){
  $count=mysql_query("select count(*) from goods  where act_shouxuanjingpin=2  and shopid = '".$_REQUEST[shopid]."'");
}

else if($_REQUEST[cityid]!=""){
  $count=mysql_query("select count(*) from goods where  act_shouxuanjingpin=2  and shopid in (select shopid from shop where city='".$_REQUEST[cityid]."')");

}

else
{
  $count=mysql_query("select count(*) from goods where  act_shouxuanjingpin=2");
}

//获得记录总数
$rs=mysql_fetch_array($count); 
$totalNumber=$rs[0];
$totalPage=ceil($totalNumber/$perNumber); //计算出总页数

if (!isset($page)) {
  $page=1;
} //如果没有值,则赋值1
$startCount=($page-1)*$perNumber; //分页开始,根据此方法计算出开始的

if($_REQUEST[keywords]!="")
{
  $rert30=mysql_query("select * from goods  JOIN shop ON shop.shopid=goods.shopid where act_shouxuanjingpin=2  and title like '".$_REQUEST[keywords]."%'  OR  shop.tel LIKE '".$_REQUEST[keywords]."%' OR shop.phone LIKE '".$_REQUEST[keywords]."%'  order by goodsid desc limit $startCount,$perNumber");
} 


else if($_REQUEST[shopid]!=""){
  $rert30=mysql_query("select * from goods where  act_shouxuanjingpin=2  and shopid = '".$_REQUEST[shopid]."' order by goodsid desc limit $startCount,$perNumber");
}

else if($_REQUEST[cityid]!=""){


  $rert30=mysql_query("select * from goods where  act_shouxuanjingpin=2  and shopid in (select shopid from shop where city='".$_REQUEST[cityid]."') order by goodsid desc limit $startCount,$perNumber");

}

else {
  $rert30=mysql_query("select * from goods  where  act_shouxuanjingpin=2  order by goodsid desc limit $startCount,$perNumber");
}       


while($sdg30=mysql_fetch_array($rert30)){
  $rert35=mysql_query("select * from shop where shopid='".$sdg30[shopid]."'");
  $sdg35=mysql_fetch_array($rert35);
  $ime=$sdg30[images];
  $de = array();
  $de=explode("," ,$ime);
  $images=$de[0];
// 分类
  $query=mysql_query("select * from categroy where cateid='".$sdg35[leimu]."'");
  $categroy=mysql_fetch_assoc($query);
// 分类 end
// 子分类
  $query=mysql_query("select * from zifenlei where id='".$sdg30[zixilie]."'");
  $zifenlei=mysql_fetch_assoc($query);
// 子分类 end
  ?>
  <tr>

    <td scope="col"><input type="checkbox" name="checkbox[]" id="checkbox" class="checkbox" value="<?php echo $sdg30[goodsid];?>"/></td>
    <td scope="col">
        <div class="youse">
        <a href="?check=1&goodsid=<?php echo $sdg30[goodsid];?>">是</a>
        </div>
        <div class="youse2">
          <a href="?check=2&goodsid=<?php echo $sdg30[goodsid];?>">否</a>
        </div>

    </td>
    <td scope="col">
      <?php if ($sdg30[check]==0) { ?>
        待审核
      <?php }elseif ($sdg30[check]==1) { ?>
        审核通过
      <?php }elseif ($sdg30[check]==2) { ?>
        未审核通过
      <?php } ?>
    </td>

    <td scope="col">
      <?php if($sdg30[xihuan]==1){?>
          <div class="youse">
             <a href="?xihuans=0&id=<?php echo $sdg30[goodsid];?>&shopid=<?php echo $_REQUEST[shopid]; ?>&shop=<?php echo $_REQUEST[shop]; ?>&cityid=<?php echo $_REQUEST[cityid]; ?>&id=<?php echo $_REQUEST[id]; ?>">取消喜欢</a>
          </div>
      <?php }else{?>
          <div class="youse2">
             <a href="?xihuans=1&id=<?php echo $sdg30[goodsid];?>&shopid=<?php echo $_REQUEST[shopid]; ?>&shop=<?php echo $_REQUEST[shop]; ?>&cityid=<?php echo $_REQUEST[cityid]; ?>">猜你喜欢</a>
          </div>
      <?php }?>

    </td>
    <?php
    if (!empty($sdg35[city])) {
      $query = mysql_query("select * from city where id = ".$sdg35[city]);
      $city = mysql_fetch_assoc($query); 
    }
    ?>
    <td scope="col"><?php echo $city[name];?><?php echo $sdg35[quyu];?></td>
    <td scope="col"><?php echo $sdg35[name];?></td>
    <td scope="col"><?php echo $sdg30[xihuan];?></td>
    <td scope="col"><img src="<?php echo $images;?>" height="50" width="50"/></td>
    <td scope="col"><?php echo $sdg30[title];?></td>
    <td scope="col"><?php echo $categroy[name];?>-<?php echo $zifenlei[name];?></td>
    <td scope="col"><?php echo $sdg30[price];?></td>
    <td scope="col"><?php echo $sdg30[xiaoliang];?></td>
    <td scope="col"><div class="youse"><a href="addgoods.php?gid=<?php echo $sdg30[goodsid];?>&keywords=<?php echo $_REQUEST[keywords]; ?>&shopid=<?php echo $_REQUEST[shopid]; ?>&shop=<?php echo $_REQUEST[shop]; ?>&cityid=<?php echo $_REQUEST[cityid]; ?>&id=<?php echo $_REQUEST[id]; ?>">编辑商品</a></div>
    <div class="youse2"><a href="addgoodsimg.php?id=<?php echo $sdg30[goodsid];?>">商品图库</a></div>
   <!--  <?php if ($sdg30[recommend] == 0) { ?>
   <div class="youse2">
     <a href="shouxuanjingpin_goods.php?recommend=1&goodsid=<?php echo $sdg30[goodsid];?>">选为推荐</a>
   </div>
   <?php }else{ ?>
   <div class="youse">
     <a href="shouxuanjingpin_goods.php?recommend=0&goodsid=<?php echo $sdg30[goodsid];?>">取消推荐</a>
   </div>
   <?php } ?> -->

    <?php if ($sdg30[tejia] =="0") { ?>
    <div class="youse2">
      <a href="shouxuanjingpin_goods.php?tejia=1&goodsid=<?php echo $sdg30[goodsid];?>">选为特价</a>
    </div>
    <?php }else{ ?>
    <div class="youse">
      <a href="shouxuanjingpin_goods.php?tejia=0&goodsid=<?php echo $sdg30[goodsid];?>">取消特价</a>
    </div>
    <?php } ?>

    <?php if ($sdg30[act_saohuo] =="0") { ?>
    <div class="youse2">
      <a href="shouxuanjingpin_goods.php?act_saohuo=2&id=<?php echo $sdg30[goodsid];?>">选为扫货</a>
    </div>
    <?php }else{ ?>
    <div class="youse">
      <a href="shouxuanjingpin_goods.php?act_saohuo=0&id=<?php echo $sdg30[goodsid];?>">取消扫货</a>
    </div>
    <?php } ?>

    <?php if ($sdg30[act_xianshizhekou] =="0") { ?>
    <div class="youse2">
      <a href="shouxuanjingpin_goods.php?act_xianshizhekou=2&id=<?php echo $sdg30[goodsid];?>">选为限时折扣</a>
    </div>
    <?php }else{ ?>
    <div class="youse">
      <a href="shouxuanjingpin_goods.php?act_xianshizhekou=0&id=<?php echo $sdg30[goodsid];?>">取消限时折扣</a>
    </div>
    <?php } ?>

    <?php if ($sdg30[act_shouxuanjingpin] =="0") { ?>
    <div class="youse2">
      <a href="shouxuanjingpin_goods.php?act_shouxuanjingpin=2&id=<?php echo $sdg30[goodsid];?>">选为首选精品</a>
    </div>
    <?php }else{ ?>
    <div class="youse">
      <a href="shouxuanjingpin_goods.php?act_shouxuanjingpin=0&id=<?php echo $sdg30[goodsid];?>">取消首选精品</a>
    </div>
    <?php } ?>

    <?php if ($sdg30[act_nixiangyaode] =="0") { ?>
    <div class="youse2">
      <a href="shouxuanjingpin_goods.php?act_nixiangyaode=2&id=<?php echo $sdg30[goodsid];?>">选为你想要的</a>
    </div>
    <?php }else{ ?>
    <div class="youse">
      <a href="shouxuanjingpin_goods.php?act_nixiangyaode=0&id=<?php echo $sdg30[goodsid];?>">取消你想要的</a>
    </div>
    <?php } ?>

    </td>
  </tr>
  <?php }?>
</table>
</form>
<div class="grid_12">

  <div class="clearfix">
    <input  type="checkbox"  id="checkbox" class="checkall"/>全选&nbsp;&nbsp;
    <input  type="button" value="删除选中"  class="submit del" />
    <input  type="button" value="一键审核通过"  class="passall submit" />
  </div>

  <ul id="pagination">

    <?php  

    if ($page > 1) { //上一页 ?>
    <li><a     href="?page=1&keywords=<?php echo $_REQUEST[keywords]; ?>&shopid=<?php echo $_REQUEST[shopid]; ?>&shop=<?php echo $_REQUEST[shop]; ?>&cityid=<?php echo $_REQUEST[cityid]; ?>&id=<?php echo $_REQUEST[id]; ?>">首页</a></li>
    <li><a     href="?page=<?php echo ($page-1); ?>&keywords=<?php echo $_REQUEST[keywords]; ?>&shopid=<?php echo $_REQUEST[shopid]; ?>&shop=<?php echo $_REQUEST[shop]; ?>&cityid=<?php echo $_REQUEST[cityid]; ?>&id=<?php echo $_REQUEST[id]; ?>">上一页</a></li>
    <?php }

    ?>

    <li class="active"><?php echo $page;?></li>

    <?php

    if ($_GET[page]!=$totalPage) { //下一页 ?>
    <li><a     href="?page=<?php echo ($page+1); ?>&keywords=<?php echo $_REQUEST[keywords]; ?>&shopid=<?php echo $_REQUEST[shopid]; ?>&shop=<?php echo $_REQUEST[shop]; ?>&cityid=<?php echo $_REQUEST[cityid]; ?>&id=<?php echo $_REQUEST[id]; ?>">下一页</a></li>
    <?php }

    if ($totalPage>1) { //下一页 ?>
    <li><a     href="?page=<?php echo $totalPage; ?>&keywords=<?php echo $_REQUEST[keywords]; ?>&shopid=<?php echo $_REQUEST[shopid]; ?>&shop=<?php echo $_REQUEST[shop]; ?>&cityid=<?php echo $_REQUEST[cityid]; ?>&id=<?php echo $_REQUEST[id]; ?>">尾页</a></li>

    <?php }?>
    <input type="text" class="text skip_val" style="width: 20px;height:12px;margin:0 5px;"><button class="submit skip">跳转</button>

  </ul>

</div>           

</div>

<input type="hidden" id="id" value="<?php echo $_REQUEST[id]; ?>">
<input type="hidden" id="shopid" value="<?php echo $_REQUEST[shopid]; ?>">
</body>
<script type="text/javascript">
  var id=$('#id').val();
  var shopid=$('#shopid').val();
  function add(){
    window.location.href="addgoods.php?shopid="+shopid+"&id="+id;
  }

  // 全选与反选
    $(".checkall").click(function(){
        var isChecked = $(this).prop("checked");
        $(".checkbox").prop("checked", isChecked);
    });
    $(".checkbox").click(function(){
      var flag=true;
      $(".checkbox").each(function(){
        if ($(this).prop("checked")==false) {
          flag=false;
        };
      });
      if (flag==false) {
        $(".checkall").prop("checked", false);
      }else{
        $(".checkall").prop("checked", true);
      };
    })
  // 全选与反选 end

  // 一键审核通过 
  $('.passall').click(function(){
    var goodsid = '';
    $(".checkbox").each(function(){
        if ($(this).prop("checked")) {
          goodsid += ','+$(this).val();
        };
    });
    goodsid = goodsid.substring(1);
    window.location.href = 'shouxuanjingpin_goods.php?act=passall&goodsids='+goodsid;
  })
  // 一键审核通过 end

  // 删除 
  $('.del').click(function(){
    $('#form').submit();
  })
  // 删除 end

  // 页面跳转 
  $('.skip').click(function(){
    var page = $('.skip_val').val();
    var url = "shouxuanjingpin_goods.php?shopid=<?php echo $_REQUEST[shopid]; ?>&page="+page;
    window.location.href = url;
  })
  // 页面跳转 end
</script>
</html>